package com.guigu.video.handler;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;

@Component
public class MyBatisPlusConfig implements MetaObjectHandler {
    LocalDateTime now = LocalDateTime.now();
    @Override
    public void insertFill(MetaObject metaObject) {


//        Object courseGmtCreate = getFieldValByName("gmtCreate", metaObject);
//        if(courseGmtCreate==null){
//
//        }
        this.setFieldValByName("commentCreate", now,metaObject);
        this.setFieldValByName("commentModified",now,metaObject);
        this.setFieldValByName("videoCreate",now,metaObject);
        this.setFieldValByName("videoModified",now,metaObject);
        this.setFieldValByName("viewCreate",now,metaObject);
        this.setFieldValByName("viewModified",now,metaObject);
    }

    @Override
    public void updateFill(MetaObject metaObject) {
        this.setFieldValByName("commentModified",now,metaObject);
        this.setFieldValByName("videoModified",now,metaObject);
        this.setFieldValByName("viewModified",now,metaObject);
    }
}
